<?php

class SubscriberController  {
	
	const REPLACE_CALLED_FUNC = '###curCalledFunction###';
	const REPLACE_RECEIVER = '###receiver###';
	const REPLACE_MAIL = '###mail###';
	
	public static function getMainWindow ()  {
		
// if password is not set call PasswordController
		PasswordController::getMainWindow();

		if (PasswordController::getPassed())  {

			if ($_POST['subscriberData'])  {
				SubscriberActionController::eventHandler(json_decode(stripslashes($_POST['subscriberData']), true));
			}
			else if ($_POST['subscriberEdited'])  {
				SubscriberActionController::verifyInput();
			}
			else  {
				self::getSubscribers();
			}
		
		}
		
	}
	
	public static function getEditSubscriber ($subscriber)  {
	
		$content = SubscriberModel::getEditSubscriberContent();
	
		//$content = ArrayProcessor_ArrayProcessor::replaceValue($content, $subscriber['receiver'], self::REPLACE_RECEIVER);
		$content = ArrayProcessor_ArrayProcessor::replaceValue($content, $subscriber['mail'], self::REPLACE_MAIL);
	
		SubscriberView::editSubscriber($content);
	}
	
	public static function getInsertSubscriber ()  {
			
			$data = SubscriberModel::getEditSubscriberContent();
			
			SubscriberView::editSubscriber($data);
	
		
	}
	
	public static function getSubscribers ()  {
		$data = SubscriberModel::getSubscriberData();
		$data = CryptographyProcessor_Cryptography::decryptEmails($data, PasswordController::getPassphrase());
		
		SubscriberView::listSubscriber($data);
		
		$data = SubscriberModel::getSubMenuData();
		SubscriberView::subMenuFrame($data);
	}
	
	
}